// ImageCanvas.cpp: implementation of the ImageCanvas class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ImageCanvas.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

IMPLEMENT_DYNAMIC(ImageCanvas, AWTCanvas)

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

ImageCanvas::ImageCanvas()
{
	m_image = NULL;
	m_offset = CPoint(0,0);
}

ImageCanvas::ImageCanvas(Image* image)
{
	m_image = NULL;
	m_offset = CPoint(0,0);
	setImage(image);
}

ImageCanvas::~ImageCanvas()
{
	if (m_image != NULL)
		delete m_image;
}

void ImageCanvas::setImage(Image* image)
{
	if (m_image != NULL)
		delete m_image;
	m_image = image;
}

void ImageCanvas::paint(CDC* pDC)
{
	CPoint pt = pDC->SetWindowOrg(m_offset);
	if (m_image != NULL)
		m_image->paint(pDC, this);
	pDC->SetWindowOrg(pt);	
}

CSize ImageCanvas::getPreferredSize()
{
	if (m_peer == NULL)
		return CSize(0,0);
	if (m_image == NULL)
		return CSize(0,0);
	return m_image->getSize();	
}


